package registnet.cpm.util;

/**
 * An implementation of a queue.
 */
public class Queue {
	
	/**
	 * Maximum size of the queue.
	 */
	private int max = 32767;
	
	/**
	 * The index of the head of the queue.
	 */
	private int head = 0;
	
	/**
	 * The index of the tail of the queue.
	 */
	private int tail = 0;
	
	/**
	 * The queue.
	 */
	Object data[] = new Object[max];;

	/**
	 * Default constructor.
	 */
	public Queue() {
	}

	/**
	 * Puts into queue the given object.
	 * @param o
	 */
	public void enque(Object o) {
		data[tail++] = o;
	}

	/**
	 * Removes from the queue the given object.
	 * @return the object that is removed
	 */
	public Object dequeue() {
		return data[head++];
	}

	/**
	 * Checks if the queue is empty.
	 * @return true if the queue is empty, and false otherwise.
	 */
	public boolean isEmpty() {
		if (head == tail)
			return true;
		else
			return false;
	}

	/**
	 * Returns the size of the queue.
	 * @return the size of the queue
	 */
	public int size() {
		return tail - head;
	}
}
